package com.qingke.practice1;

public class Mytime {
	private int hour;
	private int minutes;
	private int second;
	
	public Mytime(int hour,int minutes,int second){
		if((hour>23||hour<0)||(minutes>59||minutes<0)||(second<0||second>59)){
			System.out.println("invalidSetting");
			System.exit(0);
		}
		this.hour = hour;
		this.minutes = minutes;
		this.second = second;
	}
	
	public int getHour(){
		return hour;
	}
	
	public void setHour(int hour){
		if(hour>23||hour<0){
			System.out.println("invalidSetting");
			System.exit(0);
		}
		
		this.hour = hour;
	}
	
	public int getMinutes(){
		return minutes;
	}
	
	public void setMinutes(int minutes){
		if(minutes<0||minutes>59){
			System.out.println("invalidSetting");
			System.exit(0);
		}
		this.minutes = minutes;
	}
	
	public int getSecond(){
		return second;
	}
	
	public void setSecond(int second){
		if(second<0||second>59){
			System.out.println("invalidSetting");
			System.exit(0);
		}
		this.second = second;
	}
	
	public void display(){
		System.out.println( hour + ":" + minutes + ":" + second);
	}
	
	public void addMinutes(int addminutes){
		if(minutes+addminutes>59){
			minutes = minutes + addminutes - 59;
			if(hour>22){
				hour = 0 ;
			}
			hour = hour + 1;	
		}
		
		minutes = minutes + 1;
	}
	
	public void addHour(int addhour){
		if(hour+addhour>23){
			hour = hour + addhour - 23;
		}
		hour = addhour + hour;
	}
	
	public void addSecond(int addsecond){
		if(second + addsecond>59){
			second = second + addsecond -59;
			if(minutes == 59)
				minutes = 0;
			minutes+=1;
		}
		second = second + addsecond;
	}
	
	public void subSecond(int subsecond){
		if(second - subsecond<0){
			second = 59 - (subsecond - second);
			if(minutes == 0)
				minutes = 59;
			minutes-=1;
		}
		second = second - subsecond;
	}
	
	
}
